package cn.itcast.service.impl;

import cn.itcast.dao.MobileOrderDao;
import cn.itcast.pojo.Address;
import cn.itcast.pojo.Order;
import cn.itcast.pojo.Setmeal;
import cn.itcast.service.MobileAddressService;
import cn.itcast.service.MobileOrderService;
import cn.itcast.service.SetmealService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class MobileOrderServiceImpl implements MobileOrderService {
    @Autowired
    private MobileOrderDao mobileOrderDao;

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private MobileAddressService mobileAddressService;

    /**
     * 根据预约id，查询预约后的信息
     * @param id
     * @return
     */
    @Override
    public Order findOrderById(String id) {
        try {
            Order order = this.mobileOrderDao.findOrderById(id);

            System.out.println("套餐id为：" + order.getSetmealId());

            Setmeal setmeal = this.setmealService.findById(order.getSetmealId());
            Address address = this.mobileAddressService.findAddressById(order.getAddressId());

            order.setAddress(address);
            order.setSetmeal(setmeal);

            return order;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 根据姓名查询预约信息
     * @param name
     * @return
     */
    @Override
    public Order findOrderByUserName(String name) {
        return this.mobileOrderDao.findOrderByUserName(name);

    }
}
